package com.example.smarthomecontroller;

import java.util.Locale;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.ListFragment;
import android.content.Context;
import android.content.Intent;

import com.example.fragments.DummySectionFragment;
import com.example.fragments.RoomFragment;
import com.example.fragments.RoomListFragment;
import com.example.fragments.SpeechFragment;
import com.example.smarthomecontroller.Settings;

	/**
	 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
	 * one of the sections/tabs/pages.
	 */
	public class SectionsPagerAdapter extends FragmentPagerAdapter {
		Settings settings;
		public SectionsPagerAdapter(FragmentManager fm, Settings settings) {
			super(fm);
			this.settings = settings;
		}
		
		public Fragment getItem(int position) {
			// getItem is called to instantiate the fragment for the given page.
			// Return a DummySectionFragment (defined as a static inner class
			// below) with the page number as its lone argument.
			switch (position) {
			case 0:
				RoomListFragment fragment = new RoomListFragment();
				return fragment;		
			case 1:
				Fragment fragment1 = new RoomFragment();
				return fragment1;
			case 2:
				Fragment fragment2 = new SpeechFragment();				
				return fragment2;
			}
			/*
			Fragment fragment1 = new DummySectionFragment();
			Bundle args1 = new Bundle();
			args1.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
			fragment1.setArguments(args1);
			return fragment1;
			*/
			return null;
		}
		
		@Override
		public int getCount() {
			// Show 3 total pages.
			return 3;
		}
		
	

		@Override
		public CharSequence getPageTitle(int position) {
			Context context = settings.context;
			Locale l = Locale.getDefault();
			
			switch (position) {
			case 0:
				return context.getString(R.string.title_section1).toUpperCase(l);
			case 1:
				return context.getString(R.string.title_section2).toUpperCase(l);
			case 2:
				return context.getString(R.string.title_section3).toUpperCase(l);
			}
			return null;
		}

	}